import request from '../utils/request'
import { AxiosPromise } from 'axios'

export function getPlaylist(uid: string | null){//获取用户歌单
    return request({
        url: '/user/playlist',
        method: 'get',
        params: {uid: uid}
    })
}
export function getPlaylistDetail(id: string | null): AxiosPromise<any> {//获取歌单详情
    return request({
        url: '/playlist/detail',
        method: 'get',
        params: {id: id}
    })
}
export function getPlaylistSong(id: string | null): AxiosPromise<any>{
    return request({
        url: '/music/playlist',
        method: 'get',
        params: {id: id}
    })
}
export function getSongDetail(ids: string): AxiosPromise<any>{ //获取歌曲详情
    return request({
        url: '/song/detail',
        method: 'get',
        params: {ids: ids}
    })
}
export function getSongSrc(id: number | string): AxiosPromise<any> { //获取歌曲资源地址
    return request({
        url: '/song/url',
        method: 'get',
        params: {id: id}
    })
}
export function getLyric(id: string): AxiosPromise<any>{ //获取歌词
    return request({
        url: '/lyric',
        method: 'get',
        params: {id: id}
    })
}
export function downLoadSong(url: string, name: string){
    const link = document.createElement('a')
    link.style.display = 'none'
    link.href = url
    link.setAttribute("download", name)
    document.body.appendChild(link)
    link.click()
    link.remove
}